package javase.ch04;

import java.util.concurrent.CountDownLatch;


public class CountDownLatchTest {
    public static void main(String[] args) {
        CountDownLatch latch = new CountDownLatch(1); // 初始值为1,倒计时器
        Thread thread1 = new Thread(()->{

            System.out.println("C");
            try {
                latch.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("A");
        },"线程1");
        Thread thread2 = new Thread(()->{
            System.out.println("B");
            latch.countDown(); // 减1
        },"线程2");
        thread1.start();
        thread2.start();
    }
}

